<?php

namespace mpend\modules\user\controllers;

use Yii;
use mpend\components\Controller;
use mpend\modules\user\models\SigninCalendarForm;
use mpend\modules\user\models\SigninLogSearch;
use mpend\modules\user\models\SigninSearch;

/**
 * 用户签到
 *
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class SigninController extends Controller {

    public $modelClass = SigninSearch::class;

    /**
     * {@inheritdoc}
     */
    public function actions() {
        return [
            'view' => [
                'class' => 'yii\rest\ViewAction',
                'modelClass' => $this->modelClass,
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            'create' => ['POST'],
            'index' => ['GET'],
        ];
    }

    /**
     * 签到列表
     *
     * @inheritdoc
     */
    public function actionIndex() {
        /* @var $model SigninSearch */
        $model = new $this->modelClass;
        $model->user_id = $this->uid;
        return $model->search();
    }

    /**
     * 签到月份历史
     *
     * @param $month
     * @return array|SigninLogSearch|\yii\data\ActiveDataProvider|\yii\db\ActiveRecord|null
     */
    public function actionPeriod($month) {
        $model = new SigninLogSearch();
        $model->month = $month;
        $model->user_id = $this->uid;
        return $model->search();
    }

    /**
     * 今日签到
     */
    public function actionCreate() {
        $model = new SigninCalendarForm();
        $model->user_id = $this->uid;
        return $model->signin();
    }

}
